package com.china08.yxyapi.api.manage.tec.teaching.mistakes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.mistakes.TeaCenterMistakes;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.mistakes.TeaCenterMistakesRepository;
import com.china08.yxyapi.security.profile.YxyProfile;

/**
 * 教师中心任教书籍章节选择纪录
 * 
 * @author Administrator
 *
 */

@CrossOrigin
@RestController
public class TeaCenterMistakesBookContentSchController extends YxyApiBaseController {

    @Autowired
    private TeaCenterMistakesRepository teaCenterMistakesRepository;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/mistakes/bookcontent/sch", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(HttpServletRequest request, HttpServletResponse response) {
        YxyProfile yxyProfile = getProfile(request, response);
        String userId = yxyProfile.getId();
        String schoolId = yxyProfile.getSchoolId();
        TeaCenterMistakes tcm = teaCenterMistakesRepository.findOne(userId + schoolId);
        RespModel respModel = new RespModel();
        if (tcm != null) {
            // 学段
            respModel.stage = tcm.getStage();
            respModel.stageName = tcm.getStageName();
            // 学科
            respModel.subject = tcm.getSubject();
            respModel.subjectName = tcm.getSubjectName();
            // 版本
            respModel.version = tcm.getVersion();
            respModel.versionName = tcm.getVersionName();
            // 册别
            respModel.bookId = tcm.getBookId();
            respModel.bookName = tcm.getBookName();
            // 章节
            respModel.bookContent = tcm.getBookContent();
            respModel.bookContentName = tcm.getBookContentName();
        }
        return respModel;
    }

    /**
     * 响应参数
     * 
     */
    protected static class RespModel extends YxyApiRespModel {
        // 学段id
        public String stage;

        // 学段名称
        public String stageName;

        // 学科id
        public String subject;

        // 学科名称
        public String subjectName;

        // 版本id
        public String version;

        // 版本名称
        public String versionName;

        // 册别id
        public String bookId;

        // 册别名称
        public String bookName;

        // 章节id
        public String bookContent;

        // 章节name
        public String bookContentName;
    }

}
